import 'package:boss/provider/cloud_printer_provider.dart';
import 'package:boss/ui/page/printer/page/printerStepOne/printer_step_one_page.dart';
import 'package:boss/ui/widget/alert/alert.dart';
import 'package:boss/ui/widget/back_confirmation.dart';
import 'package:boss/ui/widget/center_title_app_bar.dart';
import 'package:boss/ui/widget/label_button.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:router/annotation.dart';

import 'widget/printer_step_two_browser.dart';

@RouterConfig(PrinterStepTwoPage.pageName)
class PrinterStepTwoPage extends StatefulWidget {
  static const pageName = '/printerStepTwoPage';

  @Autowired()
  final int id;

  const PrinterStepTwoPage({this.id});

  @override
  _PrinterStepTwoPageState createState() => _PrinterStepTwoPageState();
}

class _PrinterStepTwoPageState extends State<PrinterStepTwoPage> {
  @override
  void initState() {
    super.initState();

    var provider = Provider.of<CloudPrinterProvider>(
      context,
      listen: false,
    );
    provider.isEdit = widget.id != null;
  }

  @override
  Widget build(BuildContext context) {
    var isEdit = widget.id != null;

    return BackConfirmation(
      backConfirmationText: '打印机还未完成确认返回么？',
      child: Scaffold(
        appBar: CenterTitleAppBar(
          title: '${!isEdit ? '新增' : '编辑'}打印机',
          backConfirmationText: '打印机还未完成确认返回么？',
          actions: <Widget>[
            if (isEdit)
              LabelButton(
                title: '编辑打印机',
                padding: EdgeInsets.only(left: 8, top: 2, bottom: 2),
                onTap: () {
                  Navigator.pushNamed(context, PrinterStepOnePage.pageName, arguments: {
                    'id': widget.id,
                  });
                },
              )
          ],
        ),
        body: PrinterStepTwoBrowser(widget.id),
      ),
    );
  }
}
